<?php
include('member_resume_controller.php');
class OrderController extends MemberResumeController {
	
	var $name = 'Order';
	
	function __construct() {
		parent::__construct();
		array_push($this->uses, 'Order','Semina','SeminaOrder');
	}
	
	function index() {
		if(empty($this->rdAuth->id)){
			$this->redirect(FRONT_SERVER_HTTP.FRONT_SERVER_NAME.'/memberLogin/login/order');
		}
		$this->_setJobData();
	}
	
	function _setJobData() {
		$member_id = $this->rdAuth->id;
		//@author baimengzhao to _setJobData add start 2012/4/6
// 		$condition = "\"Order\".\"member_id\" = $member_id AND \"Order\".\"deleted\" is null";
// 		$order='Order.created desc';
// 		$data = $this->Order->findAll($condition,null,$order);
		$info = $this->SeminaOrder->getOrderSemina($member_id,$this->show,$this->page);		
		$data = $info['data'];
		//lfx added 2013-09-12 start
		$URLTOASIA=$this->Prop->getValue('config.URLTOASIA');
		$this->set('URLTOASIA',$URLTOASIA);
		//lfx added 2013-09-12 end
		$this->set('data', $data);
		
		//分页显示
// 		$count = $this->Order->findCount($condition);
		$count = $info['count'];
		
		//@author baimengzhao to _setJobData add end 2012/4/6
		$this->setPaging('ajax','/order/index',$count,$this->show,null,$this->show);
// 		echo 'id======>>>>>>'.$id.'<br>';
// 		echo $count.'===>>>';
		//分页总数显示
		$pagestr=$this->initPageCount($count,'件','件','中',$this->show);
		$this->set('pagestr',$pagestr);
	}

	//@author wangyuhua 2012/4/3 update start 下载履历参数解密，修改了方法参数
	function member_info_download($param){
		$params = $this->Order->decodeParam($param);
		$arr = split("/",$params);
		$order_id = $arr[0];
		$flg = $arr[1];
		//@author wangyuhua 2012/4/3 update end 下载履历参数解密
		if(empty($this->rdAuth->id)){
    		$this->redirect(FRONT_SERVER_HTTP.FRONT_SERVER_NAME.'/memberLogin/login/order');
    	}
		$order=$this->Order->find('"Order"."id"='.$order_id);
//		$this->checkAccess1($order['Order']['company_id'],$this->rdAuth->company_id);
		$job_id=$order['Order']['job_id'];
		$member_id=$order['Order']['member_id'];
		$path=null;
		if($flg==1){
			$file_name=$order['Order']['file_name'];
		}elseif($flg==2){
			$file_name=$order['Order']['file_name_2'];
		}else{
			$file_name=$order['Order']['file_name_3'];
		}
		if(!empty($file_name)){
			$path=$this->Prop->getValue('config.file.resume.dir').DS.floor($job_id/1000).DS.$job_id.DS.floor($member_id/1000).DS.$member_id;
		}else{
			exit;
		}	
		$this->FileEncrtypt->downloadFile($path,$file_name,$flg);
		exit;	
	}

	function delete_info($order_id){
		if(!empty($order_id)){
			$this->Order->dodelete($order_id);
		}
		$this->redirect('/order');
	}
	
	//@author baimengzhao to delete_semina_order add start 2012/4/6
	function delete_semina_order($semina_id){
		if(!empty($semina_id)){
			$this->SeminaOrder->dodelete($semina_id);
		}
		$this->redirect('/order');
	}
	
	//@author baimengzhao to detail_semina_order add start 2012/4/6
	function detail_semina_order($semina_id){
		
		if(empty($this->rdAuth->id)){
			$this->redirect(FRONT_SERVER_HTTP.FRONT_SERVER_NAME.'/memberLogin/login/order');
		}
		$semina_order = $this->SeminaOrder->find('"SeminaOrder"."deleted" is null and "SeminaOrder"."id" ='.$semina_id);
		
		$semina_order = $this->SeminaOrder->getSeminaOrder($semina_order);
		$this->set("semina_order", $semina_order);
	}
	
	
	/**
	 * 2.5.1共通_応募管理へ遷移するとき呼び出す
	 * 
	 * create: ???
	 * update: 2012-03-03 ツバサ
	 * */
	function detail($order_id){
		if(empty($this->rdAuth->id)){
			$this->redirect(FRONT_SERVER_HTTP.FRONT_SERVER_NAME.'/memberLogin/login/order/detail/'.$order_id);
			exit();
		}
		//@author wangyuhua 2012/4/20 start
		$memId = $this->rdAuth->id;
		$mem_orderids = $this->Order->findAll("\"Order\".member_id = ".$memId);
		$memOrderIds = array();
		foreach ($mem_orderids as $memOrderId) {
			$memOrderIds[] = $memOrderId['Order']['id'];
		}
		if (!in_array($order_id,$memOrderIds)) {
			$this->redirect('/errors/error404');
			exit;
		}
		//@author wangyuhua 2012/4/20 end
		
		$order = $this->Order->find('"Order"."deleted" is null and "Order"."id" ='.$order_id);
		
		//@author wangyuhua 2012/4/3 start 下载履历参数加密
		$param1 = $order_id."/1";
		$param2 = $order_id."/2";
		$param3 = $order_id."/3";
		$downfile1 = $this->Order->encodeParam($param1);
		$downfile2 = $this->Order->encodeParam($param2);
		$downfile3 = $this->Order->encodeParam($param3);
		//@author wangyuhua 2012/4/3 end
		
		$member_id = $order['Order']['member_id'];
		$member = $this->Member->find("\"Member\".id=" . $member_id . " and \"Member\".deleted is null");
		if(empty($member)) {
			$this->redirect(FRONT_SERVER_HTTP.FRONT_SERVER_NAME.'/memberLogin/login');
			exit();
		} else {
			$member['Member']['public_profile'] = $this->setPublicProfileFlg($member['Member']['public_profile_flg']);
			$member['Member']['visa'] = $this->setWorkVisa($member);
			$resumeData = $this->getResumeData($member_id);
			/* wang.wei 2013/01/22 update start*/
			$this->setIncome($member['Member']['hope_income'], $member['Member']['hope_income_cur'], $member['Member']['hope_income_to'],'hope_income');
			//$this->setIncome($member['Member']['hope_income'], $member['Member']['hope_income_cur']);
			/* wang.wei 2013/01/22 update end*/
			$this->memberExpToArray($member);
			$this->set("resumeData", $resumeData);
// 			$this->set("expworktype", $resumeData['expworktype']);
// 			$this->set("resume", $resumeData['resume']);
// 			$this->set("edu", $resumeData['edu']);
// 			$this->set("work", $resumeData['work']);
			$this->set("member", $member);
			$this->set('order',$order);
			
			//@author wangyuhua 2012/4/3 start 下载履历参数
			$this->set("downfile1", $downfile1);
			$this->set('downfile2',$downfile2);
			$this->set('downfile3',$downfile3);
			//@author wangyuhua 2012/4/3 end
		}
	}
}
?>